﻿using System;
using UnityEngine;
 
 namespace UFrame
{
    public class IntToSpriteConverter 
    {
        public Sprite[] spAry;
        public int[] indexAry;

        public IntToSpriteConverter()
        {
        }

        public IntToSpriteConverter(int [] indexAry, Sprite [] spAry)
        {
            this.spAry = spAry;
            this.indexAry = indexAry;
        }

        public object Convert(object value)
        {
            int index = System.Convert.ToInt32(value);
            return spAry[index];
        }

        public object ConvertBack(object value)
        {
            for (int i = 0; i < spAry.Length; i++)
            {
                if (spAry[i] == value)
                    return indexAry[i];
            }
            return 0;
        }
    }
}